/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 2.03  */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/neutrino.h>
#include <sys/dispatch.h>

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"


aircraftList al;
extern char AIRPORT_NAME[20];
int X_POSITION;
int Y_POSITION;

int
getAircrafts( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{
	PtWidget_t *this_window, *wid;
	int fd;
	packet_t send;
	packet_t reply;
	//aircraftList al;
	int counter;
	int ile_badziewia_lata;
	
	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;
	
	this_window = ApGetInstance(widget);
	
	if(ApName( widget ) == ABN_getAircraftsTimer)
	{
		if((fd = name_open(AIRPORT_NAME,NAME_FLAG_ATTACH_GLOBAL))==NULL)
		{
			printf("Transmission Interrupt\n");
			exit(1);
		}
		
		send.who=GUI;
		send.type=GUI_WANT_AIRCRAFT_DATA;

		MsgSend(fd,&send,sizeof(send),&reply,sizeof(reply));
		printf("Message from: %d value: %d\n",reply.who,reply.type);
		al = reply.listaSamolotow;
		ile_badziewia_lata = al.noOfAircrafts;
		printf("Ile samolotow: %d \n",ile_badziewia_lata);
		for(counter=0;counter<ile_badziewia_lata;counter++)
		{
			printf("%s\n",al.a[counter].aircraftName);
			printf("%d\n",al.a[counter].aircraftID);
			printf("%d\n",al.a[counter].Xposition);
			printf("%d\n",al.a[counter].Yposition);
			printf("%d\n",al.a[counter].state);
			printf("%d\n\n",al.a[counter].FuelValue);									
									
		}
		

	name_close(fd);		
	
	PtDamageWidget(ABW_Radar_PtRaw);
	PtFlush();
		
	}
	
		
	return( Pt_CONTINUE );

}

